<?php
/**
 * 金银拼列表
 *
 *
 *
 * * @网店运维 (c) 2015-2018  Inc. (http://www.shopwwi.com)
 * @license    http://www.shopwwi.c om
 * @link       交流群号：111731672
 * @since      网店运维提供技术支持 授权请购买shopnc授权
 */



defined('InShopNC') or exit('Access Invalid!');
class store_crowdlistControl extends BaseSellerControl {
    public function __construct() {
        parent::__construct();
        Language::read ('member_store_goods_index');
    }

    public function indexOp() {

        $model_crowd = Model('crowdlist');
        $condition = array();
        $curpage = empty($_GET['curpage']) ? 1:(int)$_GET['curpage'];
        $condition['store_id'] = $_SESSION['store_id'];
        if(!empty($_GET['title'])) {
            $condition['title'] = array('like', '%'.$_GET['title'].'%');
        }
        $item_list = $model_crowd->getItems($condition, '*', 'id desc',10,$curpage-1);
        Tpl::output('item_list', $item_list);
        Tpl::output('show_page', $model_crowd->showpage(2));

        Tpl::showpage('store_crowdlist.list');
    }

    public function addOp(){
        if(!empty($_POST['form_submit'])){
            $result = chksubmit(true);
           if($result){
               $model_crowd = Model("crowdlist");
               $insert_id = $model_crowd->addCrowd($_POST);
               if($insert_id){
                   showMessage('金银拼商品添加成功!','index.php?act=store_crowdlist');
               }
           }
        }else {
            if (!empty($_GET['sid'])) {
                $model_goods = Model("goods");
                $goods_info = $model_goods->getGoodsCommonInfoByID((int)$_GET['sid']);
                Tpl::output('goods', $goods_info);
            }
            Tpl::showpage('store_crowdlist.add');
        }
    }

    public function editOp(){
        if(!empty($_POST['form_submit'])){
            $result = chksubmit(true);
            if($result){
                $model_crowd = Model("crowdlist");
                $insert_id = $model_crowd->editCrowd($_POST);
                if($insert_id){
                    showMessage('金银拼商品修改成功!','index.php?act=store_crowdlist');
                }
            }
        }else{
            $id = $_GET['id'];
            $model_crowd = Model('crowdlist');
            $item = $model_crowd->getItem($id);
            Tpl::output('item',$item);
            Tpl::output('edit_goods_sign',true);
            Tpl::showpage('store_crowdlist.edit');
        }
    }

    /**
     * 编辑图片
     */
    public function edit_imageOp() {
        $id = intval($_GET['id']);
        if ($id <= 0) {
            showMessage(L('wrong_argument'), urlShop('seller_center'), 'html', 'error');
        }
        $model_crowd = Model('crowdlist');
        $image_array = $model_crowd->getGoodsImages($id);
        Tpl::output('img', $image_array);

        Tpl::output('edit_goods_sign', true);
        Tpl::showpage('store_crowdlist.images');
    }

}
